package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/*
设置事务的隔离级别
 */
public class JDBCDemo12 {
    public static void main(String[] args) {
        try (Connection conn=DBUtil.getConnection();){
            //设置隔离级别为 READ UNCOMMITTED
            conn.setTransactionIsolation(conn.TRANSACTION_READ_UNCOMMITTED);
            conn.setAutoCommit(false);
            String s="INSERT INTO userinfo(username,password,nickname,age) " +
                    "VALUES(?,?,?,?)";
            PreparedStatement ps= conn.prepareStatement(s);
            ps.setString(1,"贾六");
            ps.setString(2,"156");
            ps.setString(3,"老6");
            ps.setInt(4,25);
            int a=ps.executeUpdate();
            System.out.println(a>0?"添加成功":"添加失败");
            conn.commit();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
